﻿using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace MassIntellect.Drawing.Shapes
{
	public class Ellipse : Shape
	{
		#region Свойства

		public override GraphicsPath GraphicsPath
		{
			get
			{
				var grp = new GraphicsPath();
				grp.AddEllipse(new RectangleF(X, Y, Width, Height));
				return grp;
			}
		}

		#endregion

		#region Методы

		//public override PointF Joint(PointF pnt)
		//{
		//    PointF[] res;
		//    float xR = Width / 2, yR = Height / 2;
		//    if (xR != yR)
		//        if (Shape.JointCircleWithVector(X + xR, Y + yR, xR, X + xR, Y + yR, pnt.X, pnt.Y, out res))
		//            return res[0];
		//        else
		//            return new PointF(float.NaN, float.NaN);
		//    else
		//        if (Shape.JointEllipseWithVector(X + xR, Y + yR, xR, yR, X + xR, Y + yR, pnt.X, pnt.Y, out res))
		//            return res[0];
		//        else
		//            return new PointF(float.NaN, float.NaN);
		//}

		public override bool Contains(PointF pnt)
		{
			float rx = Width / 2, ry = Height / 2,
			      cx = X + rx, cy = Y + ry;
			var rl = Width / Height;
			var rr = Math.Sqrt(Math.Pow(cx - pnt.X, 2) + Math.Pow((cy - pnt.Y) * rl, 2));
			return rx > rr || Math.Abs(rx - rr) < .5;
		}

		public override object Clone()
		{
			var sh = base.Cloning<Ellipse>();
			return sh;
		}

		public override string ToString()
		{
			return string.Format("Эллипс({0},{1})", X, Y);
		}

		#endregion
	}
}